package com.colter.project.sample.thread.mycurrent;

/**
 * Created by liangchao on 17-11-18.
 */
public class MyThread {
    public static void main(String[] args) {
        One one = new One();
        new Thread(() -> {

            while (true) {

                one.set2();
            }
        }).start();

        new Thread(() -> {

            while (true) {
                one.set3();

            }
        }).start();

        new Thread(() -> {

            while (true) {
                one.print();

            }
        }).start();

    }
}


class One {
    private static volatile int a = 3;

    public int getA() {
        return a;
    }

    public void setA(int a) {
        this.a = a;
    }

    public void set2() {
        this.a = 2;
    }

    public void set3() {
        this.a = 3;
    }

    public void print() {
        if (this.a != 2 && this.a != 3) {
            System.out.println(a);
        }
    }

}

